<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<title>员工日报明细报表</title>
	<script type="text/javascript" src="../../js/boot.js"></script>
</head>

<body>
	<div class="mini-splitter" style="width: 100%; height: 100%;">

		<div size="240" showCollapseButton="true">
			<div class="mini-fit">
				<ul id="sortTree" class="mini-tree" style="width:258px;" showTreeIcon="true" allowDrag="true" allowDrop="true" textField="sortName"
					idField="projectSortID" resultAsTree="false">
				</ul>
			</div>
		</div>

		<div showCollapseButton="true">
			<fieldset id="fd1" style="width: 97%; margin-bottom: 10px;">
				<legend><span>查询条件</span></legend>
				<div id="queryForm" class="fieldset-body">
					<table class="form-table" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td class="form-label">
								<span>姓名：</span>
								<div id="txtUserID" class="mini-autocomplete" style="width:150px;" popupWidth="200" textField="userName" valueField="userID">
									<div property="columns">
										<div header="姓名" field="userName" width="40"></div>
										<div header="编号" field="workNo"></div>
									</div>
								</div>
								<input id="comUserID" class="mini-combobox" textField="userName" valueField="userID" style="width: 150px">
								<span>日期从：</span>
								<input id="calendarDate_from" name="calendarDate_from" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
								<span>到：</span>
								<input id="calendarDate_to" name="calendarDate_to" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-search" onclick="doSearch()">查询</a>
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-save" onclick="output()">导出</a>
							</td>
						</tr>
					</table>
				</div>
			</fieldset>

			<div class="mini-fit">
				<div id="datagrid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="20" allowResize="true" multiSelect="true">
				</div>
			</div>
		</div>
	</div>

</body>

<script type="text/javascript">
	miniInit();

	// 工时分项
	var sortTree = mini.get("sortTree");
	http.get("/oa/project/sort/list.do", function (page) {
		if (page.data.length > 0) {
			sortTree.loadList(page.data, "projectSortID", "parentID");
		} else {
			sortTree.addNode({
				projectSortID: "ROOT",
				sortName: "公司"
			}, 0, null);
		}
	});

	var userID = null;
	var localUser = mini.decode(localStorage.getItem('user'));
	if (localUser == null) {
		alert("你还没有登录，请先登录再操作...");
	}
	// 如果是普通用户，使用下拉选择控件，把本人及本人的手下加载进来
	else {
		userID = localUser.userID;
		if (localUser.roleID == "normalUser") {
			mini.get("txtUserID").setVisible(false);
			var comUserID = mini.get("comUserID");
			comUserID.setName("userID");
			http.get("/day/report/user/biz/list.do", function (page) {
				if (page.data.length > 0) {
					comUserID.setData(page.data);
					comUserID.select(0);
					comUserID.on("valuechanged", function (e) {
						// var user = e.selected;
						search();
					});
				}
			});
		}
		// 如果是平台管理员，使用自动补全控件
		else {
			mini.get("comUserID").setVisible(false);
			var txtUserID = mini.get("txtUserID");
			txtUserID.setName("userID");
			txtUserID.set({
				url: http.getUrl("/user/page.do")
			});
			txtUserID.setValue(localUser.userID);
			txtUserID.setText(localUser.userName);
		}
	}

	// 设置截止日期至今天
	var date = new Date();
	mini.get("calendarDate_to").setValue(date);
	date.setDate(date.getDate() - 5);
	mini.get("calendarDate_from").setValue(date);

	var queryForm = new mini.Form("#queryForm");
	var datagrid = mini.get("datagrid");

	function doSearch() {
		miniui.mask("数据加载中...");
		var data = queryForm.getData(true, false);
		data["departID_link"] = 'like';
		var sortNode = sortTree.getSelectedNode();
		if (sortNode) {
			data["projectSortID"] = sortNode.projectSortID;
			data["projectSortID_link"] = 'like';
		}
		data["orderBy"] = ["userID,desc", "calendarDate,desc"];
		var columns = [
			{ type: "indexcolumn" },
			{ field: "userName", width: 100, headerAlign: "center", header: "员工名称" },
			{ field: "departName", width: 100, headerAlign: "center", header: "部门名称" },
			{ field: "calendarDate", width: 100, headerAlign: "center", header: "日期" },
			{ field: "packetName", width: 100, headerAlign: "center", header: "工作包" },
			{ field: "sortName", width: 100, headerAlign: "center", header: "工时分项" },
			{ field: "drawName", width: 100, headerAlign: "center", header: "图纸名称" },
			{ field: "description", width: 100, headerAlign: "center", header: "工作说明" },
			{ field: "workTime", width: 100, headerAlign: "center", header: "工作时长" },
			{ field: "hasWorkedRate", width: 100, headerAlign: "center", header: "完成进度" }
		];
		http.post("/day/report/listDayReportDetail.do", data, function (page) {
			if (page.success) {
				if (page.dataMap.title) {
					var title = page.dataMap.title;
					for (var i = 0; i < title.length; i++) {
						columns.push({
							field: title[i],
							width: 100,
							headerAlign: "center",
							header: title[i]
						});
					}
				}
				datagrid.set({
					data: page.data,
					columns: columns
				});
			} else {
				miniui.showLoadErrorMessageBox(page.message);
			}
			mini.unmask();
		});
	}


	function output() {
		mini.mask({
			el: document.body,
			cls: 'mini-mask-loading',
			html: '数据处理中...'
		});
		var data = queryForm.getData(true, false);
		var sortNode = sortTree.getSelectedNode();
		if (sortNode) {
			data["projectSortID"] = sortNode.projectSortID;
			data["projectSortID_link"] = 'like';
		}
		data["orderBy"] = ["userID,desc", "calendarDate,desc"];
		http.post("/day/report/listDayReportDetailOutput.do", data, function (page) {
			mini.unmask();
			if (page.success) {
				mini.alert("数据处理成功，准备下载!", "提示", null);
				var url = http.getUrl("/file/any/getFile.do");
				jQuery('<form action="' + url + '"method=post">' + // action请求路径及推送方法
					'<input type="text" name="url" value="' + page.dataMap.filename + '"/>' + // 文件路径
					'</form>')
					.appendTo('body').submit().remove();
			} else {
				mini.alert(page.message, "提示", null);
			}
		});
	}
</script>

</html>